package io.gitee.zhangbinhub.admin.log.conf

import com.mybatisflex.core.FlexGlobalConfig
import com.mybatisflex.core.keygen.IKeyGenerator
import com.mybatisflex.core.keygen.KeyGeneratorFactory
import com.mybatisflex.solon.MyBatisFlexCustomizer
import io.gitee.zhangbinhub.acp.boot.log.LogAdapter
import io.gitee.zhangbinhub.acp.core.common.CommonTools
import org.noear.solon.annotation.Configuration
import org.noear.solon.annotation.Inject

/**
 * 自定义Mybatis-Flex配置
 */
@Configuration
class MybatisFlexConfiguration : MyBatisFlexCustomizer {
    class AcpUUIDKeyGenerator : IKeyGenerator {
        override fun generate(entity: Any, keyColumn: String): Any {
            return CommonTools.getUuid()
        }
    }

    override fun customize(flexGlobalConfig: FlexGlobalConfig) {
        KeyGeneratorFactory.register("AcpUUID", AcpUUIDKeyGenerator())
    }
}